{% extends 'base.html' %}
{% block head %}
	<link href="{{ path }}js/plugins/datatables/DT_bootstrap.css" rel="stylesheet">
	<link href="{{ path }}js/plugins/responsive-tables/responsive-tables.css" rel="stylesheet"> 
    
    <script src="{{ path }}js/demos/demo.tables.js"></script>
    <script src="{{ path }}js/plugins/datatables/jquery.dataTables.js"></script>
    <script src="{{ path }}js/plugins/datatables/DT_bootstrap.js"></script>
	<script src="{{ path }}js/plugins/responsive-tables/responsive-tables.js"></script>
    <script src="{{ path }}js/jquery.numeric.js"></script>
	<script src="{{ path }}js/demos/demo.ui-elements.js"></script>
	<script src="{{ path }}js/plugins/colorpicker/js/bootstrap-colorpicker.js"></script>
	<script src="{{ path }}js/plugins/timepicker/jquery.ui.timepicker.min.js"></script>
    
{% endblock %}

{% block javascript %}

function OnSubmitForm(){
	if(document.pressed == 'Exportar'){
		document.frm_filtro.action ="/inventario/informe_sismed/exportar/";
		document.frm_filtro.target = "_blank";
		return true;
	}

	if(document.pressed == 'Visualizar'){
		document.frm_filtro.action ="/inventario/informe_sismed/reporte/";
		document.frm_filtro.target = "_blank";
		return true;
	}
    
    else if(document.pressed == 'Reporte'){
		document.frm_filtro.action ="/inventario/informe_sismed/exportar/";
		document.frm_filtro.target = "_blank";
		return true;
	}
    
    else{
    	return false;
    }
}
{% endblock %}

{% block jquery %}
	buscar();

	function buscar() {
    	inicio = $('#fecha-inicio').attr('value');
        fin = $('#fecha-fin').attr('value');
        $.ajax({
            url: "/inventario/informe_sismed/buscar/",
            type: "POST",
            data : {'fecha-inicio':inicio, 
            		'fecha-fin':fin, 
                    csrfmiddlewaretoken : $('#csrf_token >div >input').attr("value")
                     },
            dataType: "html",
            success: function(datos) {
            	$('#resultados').html(datos);
            }
        });
	}
	        
	
	$("#btn_buscar").click(buscar);

    
{% endblock %}

{% block contenido %}
	{{ request.session.control }}
    	<div class="span12">
			<div id="horizontal" class="widget widget-form">
				<div class="widget-header">	      				
					<h3>
						<i class="icon-pencil"></i>
						Filtro
					</h3>
				</div> <!-- /widget-header -->
				
				<div class="widget-content">
				<form id="frm_filtro" name="frm_filtro" class="form-horizontal" onsubmit="return OnSubmitForm();" method="POST">
					{% csrf_token %}
					<div class="span6">
						<div class="control-group">
							<label class="control-label" for="bizaddress1">Fecha emisión:</label>
							<div class="controls">
								<input class="input-medium" name="fecha-inicio" id="fecha-inicio" type="text">
							</div>
						</div>
						
					</div>
					<div class="span5">
						<div class="control-group">
							<label class="control-label" for="bizaddress1">Fecha fin:</label>
							<div class="controls">
								<input class="input-medium" name="fecha-fin" id="fecha-fin" type="text">
							</div>
						</div>
						<div class="control-group">
							<div class="controls">
								<button type="submit" class="btn btn-primary btn-medium" id="btn_buscar" onclick="document.pressed=this.value" value="Buscar">Buscar</button>
								<button type="submit" class="btn btn-primary btn-medium" id="btn_visualizar" onclick="document.pressed=this.value" value="Visualizar">Visualizar</button>
								<button type="submit" class="btn btn-primary btn-medium" id="btn_exportar" onclick="document.pressed=this.value" value="Exportar">Exportar</button>
							</div>
						</div>
					</div>
				</form>
				</div> <!-- /. widget-content -->
			</div>  <!-- horizontal -->
		</div> <!-- /.span12 -->
		
		
    	<div id="resultados" class="span12">
            
        </div> <!-- /. span12 -->
        
{% endblock %}